﻿/*************************************************************************************
 * 文 件 名:   HK_TargetItem
 * 
 * 描    述:   每个目标点需挂在的脚本
 *             绿色为默认目标位置，红色为最远位置，蓝色为最近位置
 * 
 * 版    本：  V1.1
 * 创 建 者：  京产肠饭
 * 创建时间：  2021/12/8
 * 链   接：  https://gitee.com/JingChanChangFan/hk_-unity-tools
*************************************************************************************/

using UnityEngine;
using QFramework;

// 不要随便插入某个值，Inspector里选的值会串位，顺着往后加
public enum HK_TargetType
{
    None,
    Type01,
    Type02,
    Type03,
    Type04,
}

public class HK_TargetItem : MonoBehaviour, IController
{
    public IArchitecture GetArchitecture()
    {
        return HKTools_Architecture.Interface;
    }

    public Vector3 targetPos
    {
        get { return transform.position + transform.forward * targetDis; }
    }

    public Vector3 targetDir
    {
        get { return transform.position - targetPos; }
    }

    [Header("名称标记：")]
    public string target_Name;

    [Header("枚举标记：")]
    public HK_TargetType targetType;

    [Header("位置标记的半径：")]
    public float targetRadius = 1f;

    [Header("默认距离（Green）：")]
    public float targetDis = 2;
    [Header("最近距离（Blue）：")]
    public float minDis;
    [Header("最远距离（Red）：")]
    public float maxDis;

    void Start()
    {
        this.SendEvent(new Event_AddCamTarget() { _targetItem = this });

        if (target_Name == "")
        {
            target_Name = gameObject.name;
        }
    }

    // 绿色为默认目标位置，红色为最远位置，蓝色为最近位置
    void OnDrawGizmosSelected()
    {
        if (minDis > targetDis)
            minDis = targetDis;

        Gizmos.color = Color.blue;
        Gizmos.DrawRay(transform.position, transform.forward * minDis);
        Gizmos.DrawSphere(transform.position + transform.forward * minDis, targetRadius);

        Gizmos.color = Color.green;
        Gizmos.DrawRay(transform.position + transform.forward * minDis, transform.forward * (targetDis - minDis));
        Gizmos.DrawSphere(transform.position + transform.forward * targetDis, targetRadius);

        if (maxDis < targetDis)
            maxDis = targetDis;

        Gizmos.color = Color.red;
        Gizmos.DrawRay(transform.position + transform.forward * targetDis, transform.forward * (maxDis - targetDis));
        Gizmos.DrawSphere(transform.position + transform.forward * maxDis, targetRadius);
    }
}
